package com.demo.config.security.service;


import com.demo.sys.entity.resp.RespontLoginEntity;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class AccountService implements UserDetailsService {
    private PasswordEncoder pe;

    public AccountService(PasswordEncoder pe) {
        this.pe = pe;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("进来了对比页面");
        /**
         * 将数据库查询的密码写入
         */
        if (username.equals("admin")) {

            RespontLoginEntity ad = new RespontLoginEntity();
            ad.setUsername("admin");
            ad.setPassword(pe.encode("123456"));
            System.out.println("登入成功11账号正确");
            return ad;
        }
        throw new UsernameNotFoundException("账号不存在");
    }
}